misc
Class Serializer<A>

java.lang.Object
  extended by misc.Serializer<A>
Type Parameters:
A - class of the object which is serialized.

public class Serializer<A>
extends java.lang.Object

Series of methods to (un)serialize an object to a string to store it as a file.

Author:
Tim Baarslag

Constructor Summary
Serializer(java.lang.String fileName)
          Create an object to serialize a class.
Serializer(java.lang.String fileName, boolean log)
          Create an object to serialize a class.
 
Method Summary
 java.lang.String getFileName()
           
 A readFromDisk()
          Read a serialized object from a file and restore it.
 A readStringToObject(java.lang.String str)
          Converts a string back to an object.
 void writeToDisk(A a)
          Serializes an object to the specified file.
 java.lang.String writeToString(A a)
          Serializes an object to a string encoded by using Base64 to avoid characterset problems.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Serializer

public Serializer(java.lang.String fileName)
Create an object to serialize a class. The filename specifies the path in which the serialized class is stored. File not found exceptions are not reported.

Parameters:
fileName - path to file in which the serialized class is stored.

Serializer

public Serializer(java.lang.String fileName,
                  boolean log)
Create an object to serialize a class. The filename specifies the path in which the serialized class is stored.

Parameters:
fileName - path to file in which the serialized class is stored.
log - specifies if file not found exceptions should be reported.
Method Detail

readFromDisk

public A readFromDisk()
Read a serialized object from a file and restore it.

Returns:
unserialized object.

writeToDisk

public void writeToDisk(A a)
Serializes an object to the specified file.

Parameters:
a - object to be serialized.

writeToString

public java.lang.String writeToString(A a)
Serializes an object to a string encoded by using Base64 to avoid characterset problems.

Parameters:
a - object to serialize.
Returns:
serialized object.

readStringToObject

public A readStringToObject(java.lang.String str)
Converts a string back to an object.

Parameters:
str - serialized object.
Returns:
unserialized object.

getFileName

public java.lang.String getFileName()
Returns:
filename in which the object should be/is serialized.